package com.zmx.patientend.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.wang.adapters.interfaceabstract.OnItemClickListener;
import com.zmx.patientend.R;
import com.zmx.patientend.pojo.ArchivesDetails;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 程序猿：胖胖祥
 * 时 间：2020/12/4  22:39
 * 功 能：
 */
public class ArchivesDetailsAdapter extends BaseAdapterRvList<ArchivesDetailsAdapter.ViewHolder, ArchivesDetails> {

    private OrderImageAdapter adapter;

    public ArchivesDetailsAdapter(Activity activity) {
        super(activity);
    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, ArchivesDetails archivesDetails) {

        holder.describe.setText("详情描述："+archivesDetails.getContent());
        holder.t_date.setText("就诊日期："+archivesDetails.getAsktime());
        adapter = new OrderImageAdapter(mActivity);
        holder.recycler.setLayoutManager(new GridLayoutManager(mActivity, 3));
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            protected void onItemClick(View view, int position) {

                imgMax(archivesDetails.getPicture().get(position));

            }
        });
        holder.recycler.setAdapter(adapter);
        adapter.setListAndNotifyDataSetChanged(archivesDetails.getPicture());
    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {
        ArchivesDetailsAdapter.ViewHolder holder = new ArchivesDetailsAdapter.ViewHolder(inflater.inflate(R.layout.adapter_archives_details, parent, false));
        return holder;
    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.t_date)
        TextView t_date;
        @BindView(R.id.describe)
        TextView describe;
        @BindView(R.id.recycler)
        RecyclerView recycler;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }

    /**
     * 点击查看大图
     */
    public void imgMax(String url) {

        LayoutInflater inflater = LayoutInflater.from(mActivity);
        View imgEntryView = inflater.inflate(R.layout.to_view_image, null);
        // 加载自定义的布局文件
        AlertDialog dialog = new AlertDialog.Builder(mActivity).create();
        ImageView img = imgEntryView.findViewById(R.id.large_image);
        Glide.with(mActivity).load(url).error(R.drawable.icon_login_account).into(img);

        dialog.setView(imgEntryView); // 自定义dialog
        dialog.show();
        // 点击布局文件（也可以理解为点击大图）后关闭dialog，这里的dialog不需要按钮
        imgEntryView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramView) {
                dialog.cancel();
            }
        });
    }
}
